cmake_minimum_required(VERSION 3.16)
project(rga2_pre)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Find required packages
find_package(OpenCV REQUIRED)
find_package(Threads REQUIRED)

# Include directories
include_directories(
    ${CMAKE_CURRENT_SOURCE_DIR}/include
    $ENV{HOME}/sysroot/usr/include
)

# Link directories
link_directories(
    $ENV{HOME}/sysroot/usr/lib/aarch64-linux-gnu
)

# Source files
set(SOURCES
    src/main.cpp
    src/yolo5_pre.cpp
    src/rga2_wrapper.cpp
)

# Create executable
add_executable(rga2-pre ${SOURCES})

# Link libraries
target_link_libraries(rga2-pre
    ${OpenCV_LIBS}
    Threads::Threads
    rga
)

# Compiler flags
if(CMAKE_CROSSCOMPILING)
    # Cross-compilation flags for aarch64
    target_compile_options(rga2-pre PRIVATE
        -Wall
        -Wextra
        -O3
        -march=armv8-a
    )
else()
    # Native compilation flags
    target_compile_options(rga2-pre PRIVATE
        -Wall
        -Wextra
        -O3
        -march=native
    )
endif()
